﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AP.Framework.Infrastructure.Repositories.IRepositories;
using AP.Framework.Infrastructure.Entities;

namespace AP.Web.Areas.Admin.Controllers
{
    public class ChannelController : Controller
    {
        //
        // GET: /Admin/Channel/
        IChannel _channel;
        public ChannelController(IChannel channel)
        {
            _channel = channel;
        }
        public ActionResult Index()
        {
            var channelList = _channel.GetAll().OrderBy(p => p.Sequence).ToList();
            return View(channelList);
        }
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(cms_Channel module)
        {
            if (ModelState.IsValid)
            {
                _channel.Add(module);
            }
            return RedirectToAction("Index");
        }
        public ActionResult Edit(int channelId)
        {
            cms_Channel param = _channel.FindById(channelId);
            return View(param);
        }
        [HttpPost]
        public ActionResult Edit(cms_Channel module)
        {
            if (ModelState.IsValid)
            {
                _channel.Modify(module);
            }
            return RedirectToAction("Index");
        }

        public ActionResult Delete(int channelId)
        {
            cms_Channel param = _channel.FindById(channelId);
            _channel.Remove(param);
            return RedirectToAction("Index");
        }
    }
}
